package myJs.api

import myJs.myPkg.MyFetch
import myJs.tool.Pojo.TpmData
import org.scalajs.dom.window
import shared.pojo.Pojo.HeatmapData
import upickle.default.read

import scala.concurrent.ExecutionContext.Implicits.global

/**
 * Created by yz on 25/5/2022
 */
object Api {

  val apiUrl = window.location.hostname match {
    case "localhost" => "http://localhost:9000"
    case _ => "http://47.92.172.28:9004"
  }

  val basic344Tpm = Basic344TpmApi

  val expH2 = ExpH2Api

  val tpm = TpmApi

  val anno = AnnoApi

  def getBarData(geneId: String) = {
    val url = s"${Api.apiUrl}/nut/tpm/getByGeneId"
    MyFetch.getRnStr(url = s"${url}?geneId=${geneId}").map { str =>
      read[Option[TpmData]](str)
    }
  }

  def heatmapData(fileName:String) = {
    val url = s"${Api.apiUrl}/nut/heatmapData"
    MyFetch.getRnStr(url = s"${url}?fileName=${fileName}").map { str =>
      read[HeatmapData](str)
    }
  }

  def nwkData(fileName:String) = {
    val url = s"${Api.apiUrl}/nut/nwkData"
    MyFetch.getRnStr(url = s"${url}?fileName=${fileName}").map { str =>
      ujson.read(str)("str").str
    }
  }


}
